package com.service.user;

import com.dao.BaseDao;
import com.dao.user.UserDao;
import com.dao.user.UserDaoImpl;
import com.pojo.User;

import java.sql.Connection;
import java.sql.SQLException;

public class UserServiceImpl implements UserService{


    private final UserDao userDao;
    public UserServiceImpl() {
        userDao = new UserDaoImpl();
    }
    /*登录*/
    @Override
    public User Login(String userPhone, String userPassword) {
        Connection connection = null;
        User user = null;

        try {
            connection = BaseDao.getConnection();
            user =  userDao.getLoginUser(connection,userPhone);
            System.out.println("UserServiceImpl中的User："+user);
        } catch (SQLException throwables) {
            System.out.println("UserServiceImpl的Login方法异常");
            throwables.printStackTrace();
        }
        return user;
    }
    /*修改密码*/
    @Override
    public int UserchangePassword(int userId, String userPassword){
        Connection connection = null;
        int flag = 0;

        try {
            connection = BaseDao.getConnection();
            flag = userDao.UserchangePassword(connection, userId, userPassword);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return flag;

    }

    @Override
    public int RegisterUser(String userName, String userPhone, String userPassword, String userQQ, String userAddress) {
        Connection connection = null;
        int Rows = 0;//返回被修改的行数
        connection = BaseDao.getConnection();
        try {
            Rows = userDao.RegisterUser(connection,userName,userPhone,userPassword,userQQ,userAddress);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return Rows;
    }
}
